package com.changjiang.luban.utils.file;

import java.awt.*;

/**
 * ColorUtil
 * Description:
 *
 * @author nichangjiang@vip.qq.com
 * @version v0.1
 * @date 2018/6/19 - 14:24
 */
public class ColorUtil {

    public static Color parseToColor(String c) {
        Color convertedColor = Color.ORANGE;
        try {
            convertedColor = new Color(Integer.parseInt(c, 16));
        } catch (NumberFormatException e) {
            e.getStackTrace();
        }
        return convertedColor;
    }

    public static String toHexEncoding(Color color) {
        String R, G, B;
        StringBuffer sb = new StringBuffer();
        R = Integer.toHexString(color.getRed());
        G = Integer.toHexString(color.getGreen());
        B = Integer.toHexString(color.getBlue());
        R = R.length() == 1 ? "0" + R : R;
        G = G.length() == 1 ? "0" + G : G;
        B = B.length() == 1 ? "0" + B : B;
        sb.append("0x");
        sb.append(R);
        sb.append(G);
        sb.append(B);
        return sb.toString();
    }

    public static void main(String[] args){
      Color cs = ColorUtil.parseToColor("6026FF");
      System.out.println(cs);
    }

}
